package com.youth.youthservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youth.commonutils.R;
import com.youth.youthservice.entity.announcement.CourseMember;
import com.youth.youthservice.mapper.CourseMemberMapper;
import com.youth.youthservice.service.CourseMemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author huangqicai
 * @since 2023-04-24
 */
@Service
public class CourseMemberServiceImpl extends ServiceImpl<CourseMemberMapper, CourseMember> implements CourseMemberService {

    /*向课程成员表里面添加信息,用于远程调用*/
    @Override
    public boolean insertCourseMember(String courseId, String memberId) {
        CourseMember courseMember = new CourseMember();
        courseMember.setCourseId(courseId);
        courseMember.setMemberId(memberId);
        int insert = baseMapper.insert(courseMember);
        if(insert>0){
            return true;
        }
        return false;
    }

    /*根据课程id和用户id判断该用户是否具有操作权限*/
    @Override
    public R selectAuthority(String courseId, String memberId) {
        System.out.println();
        if(StringUtils.isEmpty(memberId)){
            return R.ok().code(1).message("你还没有登录，请前往登录");
        }
        List<CourseMember> courseMembers = baseMapper.selectList(new QueryWrapper<CourseMember>().eq("course_id", courseId).eq("member_id", memberId));
        if (courseMembers.isEmpty()){
            return R.ok().code(2).message("立即支付按钮显示出来");
        }

        return R.ok().code(3).message("立即观看按钮显示出来");
    }

}
